﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tetris.Interfaces;

namespace Tetris.Blocks
{
    public class SquareBlock : AbstractBlock
    {
        private Tile _topLeftTile;
        private Tile _topRightTile;
        private Tile _bottomLeftTile;
        private Tile _bottomRightTile;

        public SquareBlock(Texture2D texture, Color color, Vector2 position, int fallDelay)
        {
            Texture = texture;
            Color = color;
            Tiles = new List<ITile>();

            // setup skeleton
            _topLeftTile = new Tile(Texture, Color);
            _topRightTile = new Tile(Texture, Color);
            _bottomLeftTile = new Tile(Texture, Color);
            _bottomRightTile = new Tile(Texture, Color);
            Tiles.AddRange(new[] { _topLeftTile, _topRightTile, _bottomLeftTile, _bottomRightTile });

            Position = position;
            FallDelay = fallDelay;
            LastFallen = 0;
        }

        protected override void ReArrangeParts(Vector2 position, RotationAngle angle)
        {
            _topLeftTile.Position = new Vector2(position.X - Texture.Width / 2, position.Y - Texture.Height / 2);
            _topRightTile.Position = new Vector2(position.X + Texture.Width / 2, position.Y - Texture.Height / 2);
            _bottomLeftTile.Position = new Vector2(position.X - Texture.Width / 2, position.Y + Texture.Height / 2);
            _bottomRightTile.Position = new Vector2(position.X + Texture.Width / 2, position.Y + Texture.Height / 2);
        }

        public override void Rotate()
        {
            // Squareblock can't rotate
        }
    }
}
